<template>
  <div>
    <div v-if="dictType === ''">
      <div class="my-code">点击字典查看详情</div>
    </div>
    <div v-else>
      <!--表单组件-->
      <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="580px">
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="字典标签" prop="dictLabel">
            <el-input v-model="form.dictLabel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="字典值" prop="dictValue">
            <el-input v-model="form.dictValue" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column label="所属字典"> {{ dictType }} </el-table-column>
        <!--展示字段-->
        <el-table-column :show-overflow-tooltip="true" prop="dictLabel" label="字典名" />
        <el-table-column :show-overflow-tooltip="true" prop="dictValue" label="字典值" />
        <el-table-column label="操作" width="130px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" msg="确定删除吗,如果存在下级节点则一并删除，此操作不能撤销！" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import CRUD, { presenter, form, crud } from '@crud/crud'
import crudDictData from '@/api/system/config/dict/dict_data'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '字典值', url: 'dict/data/list/page', crudMethod: { ...crudDictData }, pkIdName: 'dictCode', query: { dictType: null }})
const defaultForm = { dictCode: null, dictLabel: null, dictValue: null, dictType: null }

export default {
  components: { udOperation, pagination },
  mixins: [presenter(defaultCrud), form(defaultForm), crud()],
  data() {
    return {
      title: '字典详情',
      dictType: '',
      permission: {
        add: [],
        edit: [],
        del: []
      },
      rules: {

      }
    }
  },
  methods: {
    [CRUD.HOOK.beforeRefresh]() {
      this.crud.query.dictType = this.dictType
      return true
    },
    [CRUD.HOOK.beforeToAdd]() {
      console.info('新增之前调用')
      this.crud.form.dictType = this.dictType
      return true
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }
</style>
